package cfdt.ldl.file.api.feign.fallback;

import cfdt.common.enums.CommonCodeEnum;
import cfdt.ldl.file.api.feign.FileFeign;
import cfdt.ldl.file.api.request.DownloadFileRequest;
import cfdt.ldl.file.api.request.UploadFileRequest;
import cfdt.ldl.file.api.response.DownloadFileResponse;
import cfdt.ldl.file.api.response.UploadFileResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import cfdt.common.vo.ObjectBaseResponse;
import feign.hystrix.FallbackFactory;

/**
 * 文件中心API-FallBack
 *
 * <pre>
 * Modify Information:
 * Author       Date          Description
 * ============ ============= ============================
 * wangxiao      2021年8月10日下午2:44:32      创建FallBack
 *
 * </pre>
 */
@Component
public class FileFallBack implements FallbackFactory<FileFeign> {
    
    private final Logger logger = LoggerFactory.getLogger(getClass().getName());

    @Override
    public FileFeign create(Throwable cause) {
        logger.error("请求文件中心异常", cause);
        return new FileFeign() {
            @Override
            public ObjectBaseResponse<DownloadFileResponse> downloadFile(DownloadFileRequest request) {
                return ObjectBaseResponse.error(CommonCodeEnum.CODE_1001);
            }

            @Override
            public ObjectBaseResponse<UploadFileResponse> uploadFile(UploadFileRequest request) {
                return ObjectBaseResponse.error(CommonCodeEnum.CODE_1001);
            }
        };
    }

}
